package logicaDePredicados;

import java.util.HashMap;

import exceptions.UnDecidibleValueException;

public class SkolemFunction<T, R> extends PredicateLogic {
	
	private HashMap <T,R> valueMap ;
	
	public SkolemFunction (String name){
		setName(name);
		valueMap = new HashMap<T, R>();
		
		
	}
	/**
	 * Add a value and a return value to the current Skolem function
	 * @param parameterValue
	 * @param returnValue
	 */
	public void addValue (T parameterValue, R returnValue){
		valueMap.put (parameterValue,returnValue);
		
	}
	/**
	 * Calculate the skolem function with the value given
	 * @param value
	 * @return the Skolem function value for the corresponding parameter value given.
	 * 
	 * @throws UnDecidibleValueException
	 */
	public PredicateConstant<R> calculate (Object value) throws UnDecidibleValueException{
		R returnValue =	valueMap.get(value);
		if (returnValue==null){
			throw new UnDecidibleValueException ("undecidible value:"+value);
		}
		return new PredicateConstant<R>(returnValue,returnValue.toString().toUpperCase());
	}
	
	public String toString (){
		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append(getName()+"\n");
		for (T iterable_element : valueMap.keySet()) {
			stringBuffer.append(iterable_element.toString()+"\t"+valueMap.get(iterable_element).toString()+"\n");
		}
		return stringBuffer.toString();
	}
	
	
}
